// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import layer from 'vue-layer'
require('es6-promise/auto')
// import Resource from "vue-resource"
import axios from 'axios';
import {
  Alert,
  Confirm,
  Toast,
  Prompt
} from 'wc-messagebox'
import 'wc-messagebox/style.css'
import moment from 'moment';

Vue.prototype.$http = axios;
Vue.prototype.$layer = layer(Vue);
// Vue.use(Resource)
Vue.use(Confirm);
Vue.use(Toast);
Vue.use(Prompt);

Vue.config.productionTip = false

/* 过滤器 */
Vue.filter("format_str", function (res) {
  let before = res.substring(0, 19);
  if (res.length <= 19)
    return before;
  else {
    let end = res.substring(20);
    return before + end;
  }
});

Vue.filter("format_date", function (res) {
  return moment(res).format('YYYY-MM-DD')
});

Vue.filter("format_num", function (res) {
  let re = res.split('.');
  if (re.length == 2) {
    let re2 = re[1].substring(0, 2)
    let re3 = re[0] + '.' + re2;
    return re3;
  }
  return res;
  // return Math.floor(res)
});

Vue.directive('focus', {　　　　
  bind: function (el, binding) {　
    console.log(el)
    el.focus();　　
    console.log('bind:', binding.value);　　
  },
  inserted: function (el, binding) {　　
    el.focus();　　　
    console.log('insert:', binding.value);　　
  },
  　　update: function (el, binding, vnode, oldVnode) {　　　　
    el.focus();　　　　
    console.log(el.dataset.name); //这里的数据是可以动态绑定的
    　　　　
    /* console.table({　　　　　　
      name: binding.name,
      　　　　　　value: binding.value,
      　　　　　　oldValue: binding.oldValue,
      　　　　　　expression: binding.expression,
      　　　　　　arg: binding.arg,
      　　　　　　modifiers: binding.modifiers,
      　　　　　　vnode: vnode,
      　　　　　　oldVnode: oldVnode　　　　
    });　 */
    　
  },
  componentUpdated: function (el, binding) {　
    el.focus();　　　　
    console.log('componentUpdated:', binding.name);　　
  }
});

axios.interceptors.request.use(config => {
  config.headers.Authorization = localStorage.getItem("token");
  return config;
}, err => {
  return Promise.reject(err);
});
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: {
    App
  }
})
